class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_action :authenticate_admin!
  before_action :check_permission!, only: [:new, :create, :edit, :update, :destroy]
  before_action :set_current_url

  def not_found
    raise ActionController::RoutingError.new('Not Found')
  end

  def last_url
    session[:url]
  end

  private
  def set_current_url
    session[:url] = request.original_url if request.get?
  end

  def check_permission!
    # code here
  end
end
